{extend name="public/base" /}
{block name="content" /}
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li class="active">
                <i class="fa fa-home"></i>&nbsp;卡密管理
            </li>
            <li>卡密列表</li>
        </ul>
    </div>
    <!-- /Page Breadcrumb -->
    <!-- Page Body -->
    <div class="page-body">
        <a href="{:url('admin/card/cardadd')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;卡密添加</a>
        <div class="row">


            <div class="col-sm-12">
                <div class="form-group col-sm-12">
                    <label for="cardtype_id" class="control-label col-sm-2 no-padding-right">对应卡密类型</label>
                    <div class="col-sm-6">
                        <select id="cardtype_id" name="cardtype_id" class="form-control">
                            {volist name="cardtypes" id="vo"}
                            <option value="{$vo.id}"{if $cardtypesvalue == $vo.id}selected{/if}>{$vo.cardtypename}</option>
                            {/volist}
                        </select>

                    </div>
                </div>
                <div class=" col-sm-3">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" id="cbx" {if $startext == true }checked{/if}>
                            <span id="startext" class="text">仅未启用</span>
                        </label>
                    </div>
                </div>

                <div class=" col-sm-3">
                    <div class="btn-group">
                        <a type="button" class="btn btn-primary pull-right cardquery" data-toggle="button">查询</a>
                    </div>
                    <div class="btn-group">
                        <a href="{:url('admin/card/cardExcel')}" class="btn btn-primary " >导出Excel</a>
                    </div>
                </div>
            </div>

            <div class="col-xs-12">
                <div class="widget">
                    <div class="widget-header">
                        <span class="widget-caption">卡密列表</span>
                        <div class="widget-buttons">
                            {$cards->render()|raw|replace}
                        </div>
                    </div>

                    <div class="widget-body">
                        <table class="table table-hover table-bordered">
                            <thead>
                                <tr>
                                    <th>排序</th>
                                    <th>卡密KEY</th>
                                    <th>程序类型</th>
                                    <th>卡密种类</th>
                                    <th>卡密状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {volist name="cards" id="vo"}
                                <tr>
                                    <td>
                                        {$vo.id}
                                    </td>
                                    <td>{$vo.cardname}</td>
                                    <td>{$vo.cardtype.software.softwarename}</td>
                                    <td>{$vo.cardtype.cardtypename}</td>
                                    <td>
                                        {if $vo.cardstar_time == ""}未启用
                                        {else /}启用
                                        {/if}

                                    </td>
                                    <td>
                                        <a href="{:url('admin/card/cardedit', ['id' => $vo.id])}"
                                            class="btn btn-azure btn-xs">查看</a>
                                        <a href="#" class="btn btn-danger btn-xs cardDel" dataid="{$vo.id}">删除</a>
                                    </td>
                                </tr>
                                {/volist}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /Page Body -->
</div>
{/block}
{block name="js"}
{__block__}
<script>
    $(function () {
        $('.pagination').addClass('pagination-sm');

        $('.cateSort').change(function () {
            var id = $(this).attr('dataid');
            var sort = $(this).val();
            $.ajax({
                url: "{:url('admin/cate/sort')}",
                type: 'post',
                data: { id: id, sort: sort },
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function () {
                            location.href = data.url;
                        });
                    } else {
                        layer.open({
                            title: '排序失败',
                            content: data.msg,
                            icon: 5,
                            anim: 6
                        });
                    }
                }
            });
        });
    });

    $('.cardDel').click(function () {
        var id = $(this).attr('dataid');
        layer.confirm('确定删除吗？', {
            title: '删除栏目',
            icon: 3,
            anim: 6
        }, function (index) {
            layer.close(index);
            $.ajax({
                url: "{:url('admin/card/carddel')}",
                type: 'post',
                data: { id: id },
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function () {
                            location.href = data.url;
                        });
                    } else {
                        layer.open({
                            title: '删除失败',
                            content: data.msg,
                            icon: 5,
                            anim: 6
                        });
                    }
                }
            });
        });
        return false;
    });

    $('.cardquery').click(function () {
        var startext =$('#cbx').is(':checked');
        var cardtypesvalue=$('#cardtype_id').val();
            $.ajax({
                url: "{:url('admin/card/cardlist')}",
                type: 'post',
                data: { startext: startext ,cardtypesvalue:cardtypesvalue},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function () {
                            location.href = data.url;
                        });
                    } else {
                        layer.open({
                            title: '查询失败',
                            content: data.msg,
                            icon: 5,
                            anim: 6
                        });
                    }
                }
            });
        
        return false;
    });
</script>
{/block}